package pyip.lib.javalearn.classloader.load;

public class Main {
    public static void main(String args[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        // A a = new A();
        // a.print();
        // B b = new B();
        // b.print();
        // new A();

        System.out.println("cl: " + Main.class.getClassLoader());
        System.out.println("cl's cl: " + Main.class.getClassLoader().getClass().getClassLoader());
        System.out.println("cl parent: " + Main.class.getClassLoader().getParent());
        System.out.println("cl parent's cl: " + Main.class.getClassLoader().getParent().getClass().getClassLoader());
        System.out.println("cl parent's parent: " + Main.class.getClassLoader().getParent().getParent());

        ClassLoader sysCL = Thread.currentThread().getContextClassLoader();

        ClassA ains = (ClassA) Class.forName("classloader.load.A", false, ClassLoader.getSystemClassLoader()).newInstance();
        Thread.currentThread().setContextClassLoader(sysCL.getParent());
        System.out.println("\n\tA: " + ains.getClass().getClassLoader());

        System.out.println("\n\tContextClassLoader: " + Thread.currentThread().getContextClassLoader());

        @SuppressWarnings("unused")
        ClassB b = new ClassB();
        System.out.println("\n\tB: " + ClassB.class.getClassLoader());

        Class<?> aclass = Class.forName("classloader.load.B");
        System.out.println("\n\tB: " + aclass.getClassLoader());

        // Class.forName("classloader.B", false, .getContextClassLoader());
    }
}
